Ext.define('XTFrame.controller.system.SQLManager', {
	extend: 'Ext.app.Controller',
	init: function(){
		this.control({
			'systemSQLModuleTree': {
				itemclick: function(tree, record, item, index, e){
					var layout = tree.up('panelBorder');
					var grid = layout.down('systemSQLManager');
//					console.log(record.data);
					grid.moduleText.setText("<font color='green'>"+record.data.text+"</font>");
					grid.modid = record.raw ? record.raw.id : record.data.id;
					grid.getStore().loadPage(1);
				},
				initcomplete: function(tree){
					this.refreshMenu(tree);
				}
			},
			'systemSQLModuleTree tool[type=refresh]': {
				click: function(o, e){
					this.refreshMenu(o.up('systemSQLModuleTree'));
				}
			},
			'systemSQLManager': {
				beforeupdate: function(grid, win, mark, opt){
					if(mark == 'editsave'){
						if(win.flag == 'add'){
							var panel = win.down('form');
							var form = panel.getForm();
							form.findField("modid").setValue(grid.modid);
						}
					}
				}
			}
		});
	},
	refreshMenu: function(tree){
		var data, treeData = ajaxUtil.executeQuery('xtframe_module_tree_0', {});
		if(!ajaxUtil.isSucceed(treeData)){
			Ext.xtframe.msg("提示", "模块数据获取失败！");
		} else {
			data = pubOPT.easyTreeNodeUtil(treeData.arrData, {id:'modid', name:'modname', pid:'parentmodid'});
			tree.getRootNode().removeAll(true);
			tree.getRootNode().appendChild(data);
			tree.expandAll();
		}
	}
});